#include<queue>
#include<algorithm>
using namespace std;
class KthLargest {
private:
    //top k问题 用小堆
    priority_queue<int,vector<int>,greater<int>> heap;
    int k;
public:
    KthLargest(int _k, vector<int>& nums)
    :k(_k),heap(nums.begin(),nums.end())
    {;}
    //堆的pop是从顶出
    int add(int val) {
        heap.push(val);
        //把小的都排除 堆里始终是最大的k个
        while(heap.size()>k)
            heap.pop();
        return heap.top();
    }
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(val);
 */